import { reqCategoryList, reqBannerList, reqFloorList } from "@/api";
const state = {
  categoryList: [],
  bannerList: [],
  floorList: [],
};
const mutations = {
  SET_CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList;
  },
  SET_BANNERLIST(state, bannerList) {
    state.bannerList = bannerList;
  },
  SET_FLOORLOST(state, floorList) {
    state.floorList = floorList;
  },
};
const actions = {
  async getCategoryList({ commit }) {
    let result = await reqCategoryList();
    if (result && result.code == 200) {
      commit("SET_CATEGORYLIST", result.data);
    } else {
      alert("获取参数失败");
    }
  },
  async getBannerList({ commit }) {
    let result = await reqBannerList();
    try {
      console.log(result);
      if (result && result.code == 200) {
        commit("SET_BANNERLIST", result.data);
        console.log(1);
      }
    } catch (error) {
      alert('获取轮播图失败')
      console.error(error);
    }
  },
  async getFloorList({ commit }) {
    let result = await reqFloorList();
    try {
      if (result && result.code == 200) {
        commit("SET_FLOORLOST", result.data);
      }
    } catch (error) {
      alert('获取楼层失败')
      console.error(error);
    }
  },
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
